package com.emser.unc.server.domain;

import java.util.Date;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Sequence;
import javax.jdo.annotations.SequenceStrategy;

import com.emser.unc.serializable.NoSaleReportDTO;
import com.google.appengine.api.datastore.Key;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
@Sequence(name = "seqNSR", strategy = SequenceStrategy.NONTRANSACTIONAL,extensions = @Extension(vendorName = "datanucleus", key="key-cache-size", value="12"))
public class NoSaleReport {
	@PrimaryKey
	@Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
	private Key key;
	@Persistent
	private Long id;
	@Persistent
	private String sellerUserName;
	@Persistent
	private Long customerID;
	@Persistent
	private Integer code;
	@Persistent
	private Date date;
	@Persistent
	private String reason;
	@Persistent
	private UserAccount userA;
	
	public Integer getCode() {
		return code;
	}
	public void setCode(Integer code) {
		this.code = code;
		setReason(code);
	}
	public String getReason() {
		return reason;
	}
	private void setReason(Integer code) {
		 switch(code) {
		 case 1: 
			 this.reason = "Cerrado.";
		     break;
		 case 2: 
			 this.reason = "Sin Dinero.";
		     break;
		 case 3: 
			 this.reason = "No esta el comprador.";
		     break;
		 case 4: 
			 this.reason = "No quiere servicio.";
		     break;
		 default: 
			 this.reason = "No especificado.";
		     break;
		 }
	}
	public Key getKey() {
		return key;
	}
	public void setId() {
		this.id = key.getId();
	}
	public Long getId() {
		return id;
	}
	public void setSellerUserName(String sellerUserName) {
		this.sellerUserName = sellerUserName;
	}
	public String getSellerUserName() {
		return sellerUserName;
	}
	public void setCustomerID(Long customerID) {
		this.customerID = customerID;
	}
	public Long getCustomerID() {
		return customerID;
	}
	public UserAccount getUserA() {
		return userA;
	}
	public static NoSaleReportDTO toDTO(NoSaleReport saleNoReport) {
	    if (saleNoReport == null) {
	      return null;
	    }
	    NoSaleReportDTO saleNoReportDTO = new NoSaleReportDTO();
	    saleNoReportDTO.setIdReport(saleNoReport.getId());
	    saleNoReportDTO.setCode(saleNoReport.getCode());
	    saleNoReportDTO.setCustomerID(saleNoReport.getCustomerID());
	    saleNoReportDTO.setSellerUserName(saleNoReport.getSellerUserName());
	    saleNoReportDTO.setDate(saleNoReport.getDate());
	    return saleNoReportDTO;
	}
	public void setDate(Date date) {
		this.date = date;
	}
	public Date getDate() {
		return date;
	}
}
